package ptumall.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import ptumall.dao.ArticleDao;
import ptumall.model.HealthArticle;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ArticleService {
    private final ArticleDao articleDao;

    public PageInfo<HealthArticle> getArticles(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<HealthArticle> list = articleDao.selectArticles();
        return new PageInfo<>(list);
    }

    public PageInfo<HealthArticle> searchArticles(String keyword, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<HealthArticle> list = articleDao.searchArticles(keyword);
        return new PageInfo<>(list);
    }

    public HealthArticle getDetail(Long id) {
        articleDao.updateViewCount(id);
        return articleDao.selectById(id);
    }
}
